package dev.ece.core.sprite;

import dev.ece.core.cells.alpha.Alpha;
import dev.ece.core.cells.model.Model;
import dev.ece.core.cells.shadow.Shadow;
import dev.ece.core.texture.FBOS;
import dev.ece.util.tools.Camera;

/**
 * 精灵类
 * @author 飘渺青衣
 * <b>E-mail：</b>3375758@qq.com
 */
public class Sprite<V, M extends Model<V>> extends AbstractSprite implements Shadow, Alpha {
	
	private M model;
	
	private V value;
	
	private boolean normal = true;
	
	private boolean alpha;
	
	public Sprite(M model) {
		this.model = model;
	}

	@Override
	public void clearup() {}

	@Override
	public void onLogic(Camera camera) {}

	@Override
	public boolean isNormalRender() {
		return normal;
	}

	@Override
	public boolean isAlphaRender() {
		return alpha && super.isAlphaRender();
	}

	public void setNormal(boolean normal) {
		this.normal = normal;
		this.alpha = !normal;
	}

	public void setAlpha(boolean alpha) {
		this.alpha = alpha;
		this.normal = !alpha;
	}

	@Override
	public void onInitialize() {
		this.model.initialize();
	}

	@Override
	public void onRenderDepthMap(Camera camera) {
		this.model.renderDepthMap(camera, value);
	}

	@Override
	public void onRender(Camera camera) {
		this.model.render(camera, value);
	}

	@Override
	public void onRenderAlpha(FBOS defer, Camera camera) {
		this.model.renderAlpha(defer, camera, value);
	}

	@Override
	public void destroy() {
		super.destroy();
		if(model != null) {
			model.destroy();
			model = null;
		}
	}

	public M getModel() {
		return model;
	}
	
	protected void setModel(M model) {
		this.model = model;
	}

	public V getValue() {
		return value;
	}

	public void setValue(V value) {
		this.value = value;
	}

}
